﻿using Evan.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Xml;

namespace Evan.DataBase
{
    /// <summary>
    /// 作者 : 张澎
    /// 时间 : 2017年4月28日01:05:10
    /// 说明 : DynamicModel 操作类 , 数据库操作类 核心类
    /// </summary>
    public class DbOperat
    {
        private IDbOperat dbOperat;


        #region 公有属性
        private string _TableName = "";
        /// <summary>
        /// 
        /// </summary>
        public string TableName
        {
            set { _TableName = value; }
            get { return this._TableName; }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 初始化一个表结构 使用 默认 链接字符串
        /// </summary>
        public DbOperat()
        {
            //WebConfig配置的默认连接字符串
            var curConnName = System.Configuration.ConfigurationManager.AppSettings["DefaultConnStr"].ToString();
            //连接字符串
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[curConnName].ConnectionString;
            //获取链接字符串 数据库类型 System.Data.SqlClient MySql.Data.MySqlClient
            string connectionProvider = System.Configuration.ConfigurationManager.ConnectionStrings[curConnName].ProviderName;


            switch (connectionProvider.ToLower())
            {
                case "system.data.sqlclient":
                    dbOperat = new MsSql.DbOperat();
                    break;
                case "mysql.data.mysqlclient":
                    dbOperat = new MySql.DbOperat();
                    break;
            }
        }



        /// <summary>
        /// 初始化一个表结构 使用 默认 链接字符串
        /// </summary>
        /// <param name="tabName">表名</param>
        public DbOperat(string tabName)
        {
            //WebConfig配置的默认连接字符串
            var curConnName = System.Configuration.ConfigurationManager.AppSettings["DefaultConnStr"].ToString();
            //连接字符串
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[curConnName].ConnectionString;
            //获取链接字符串 数据库类型 System.Data.SqlClient MySql.Data.MySqlClient
            string connectionProvider = System.Configuration.ConfigurationManager.ConnectionStrings[curConnName].ProviderName;


            switch (connectionProvider.ToLower())
            {
                case "system.data.sqlclient":
                    dbOperat = new MsSql.DbOperat(tabName);

                    break;
                case "mysql.data.mysqlclient":
                    dbOperat = new MySql.DbOperat();
                    break;
            }
            SetTable(tabName);

        }


        /// <summary>
        /// 初始化一个表结构 使用 默认 链接字符串
        /// </summary>
        /// <param name="connName">链接字符串</param>
        /// <param name="tabName">表名</param>
        public DbOperat(string connName, string tabName)
        {
            //连接字符串
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[connName].ConnectionString;
            //获取链接字符串 数据库类型 System.Data.SqlClient MySql.Data.MySqlClient
            string connectionProvider = System.Configuration.ConfigurationManager.ConnectionStrings[connName].ProviderName;


            switch (connectionProvider.ToLower())
            {
                case "mssql":
                    dbOperat = new MsSql.DbOperat(connName, tabName);
                    SetTable(tabName);
                    break;
                case "mysql":
                    dbOperat = new MySql.DbOperat();
                    break;
            }
            SetTable(tabName);

        }

        #endregion


        #region 设置操作表
        /// <summary>
        /// 设置操作表
        /// </summary>
        /// <param name="tabName"></param>
        /// <returns></returns>
        public DbOperat SetTable(string tabName)
        {
            return dbOperat.SetTable(this, tabName);
        }
        #endregion




        #region GetModel 方法 - OK
        /// <summary>
        /// 获取当前实例对象后的某个表中的所有字段 通过ID
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public dynamic GetModel(int Id)
        {
            return dbOperat.GetModel(TableName, Id);
        }
        /// <summary>
        /// 获取当前实例对象后的某个表中的指定字段 通过ID
        /// </summary>
        /// <param name="Fields">字段 Id,Title</param>
        /// <param name="Id">查询的参数</param>
        /// <returns></returns>
        public dynamic GetModel(string Fields, int Id)
        {
            return dbOperat.GetModelSomeField(TableName, Fields, "Id=@Id", Id);
        }
        /// <summary>
        /// 获取当前实例对象后的指定表中的指定字段 通过ID
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Fields"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        public dynamic GetModel(string TableName, string Fields, int Id)
        {
            return dbOperat.GetModelSomeField(TableName, Fields, "Id=@Id", Id);
        }

        /// <summary>
        /// 通过Where 获取单条数据
        /// </summary>
        /// <param name="Where">where 语句  注意 : 不用写where</param>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public dynamic GetModel_1(string Where, params object[] param)
        {
            return dbOperat.GetModel(TableName, Where, param);
        }
        /// <summary>
        /// 通过Where 获取单条数据
        /// </summary>
        /// <param name="Fields">字段名 Id,Title</param>
        /// <param name="Where">where 语句  注意 : 不用写where</param>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public dynamic GetModel_2(string Fields, string Where, params object[] param)
        {
            return dbOperat.GetModelSomeField(TableName, Fields, Where, param);
        }
        /// <summary>
        /// 通过Where 获取单条数据
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Fields">字段名 Id,Title</param>
        /// <param name="Where">where 语句  注意 : 不用写where</param>
        /// <param name="param">参数列表</param>
        /// <returns></returns>
        public dynamic GetModel_3(string TableName, string Fields, string Where, params object[] param)
        {
            return dbOperat.GetModelSomeField(TableName, Fields, Where, param);
        }

        ///// <summary>
        ///// 获取 单条中的部分字段
        ///// </summary>
        ///// <param name="DataBase">指定数据库 , 数据库必须是在链接字符串中配置过的</param>
        ///// <param name="TableName">指定表名</param>
        ///// <param name="Fields">指定获取那些字段</param>
        ///// <param name="Where">Where 条件</param>
        ///// <param name="param">参数列表</param>
        ///// <returns></returns>
        //private dynamic GetModelField(string DataBase, string TableName, string Fields, string Where, params object[] param)
        //{

        //}
        #endregion

        #region GetList 方法 - OK

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Where">条件</param>
        /// <returns></returns>
        public List<dynamic> GetList(string Where)
        {
            return dbOperat.GetList(TableName, Where);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Top">前几条</param>
        /// <param name="Where">条件</param>
        /// <returns></returns>
        public List<dynamic> GetList(int Top, string Where)
        {
            return dbOperat.GetList(TableName, Top, Where);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Where">条件</param>
        /// <param name="Order">排序</param>
        /// <returns></returns>
        public List<dynamic> GetList(string Where, string Order)
        {
            return dbOperat.GetList(TableName, Where, Order);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Top">前几条</param>
        /// <param name="Where">条件</param>
        /// <param name="Order">排序</param>
        /// <returns></returns>
        public List<dynamic> GetList(int Top, string Where, string Order)
        {
            return dbOperat.GetList(TableName, Top, Where, Order);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Top">前几条</param>
        /// <param name="Where">条件</param>
        /// <param name="Order">排序</param>
        /// <param name="param">参数化语句的参数</param>
        /// <returns></returns>
        public List<dynamic> GetList_1(int Top, string Where, string Order, params object[] param)
        {
            return dbOperat.GetList(TableName, Top, Where, Order, param);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="Top">前几条</param>
        /// <param name="Fields">那些字段</param>
        /// <param name="Where">条件</param>
        /// <param name="Order">排序</param>
        /// <param name="param">参数化语句的参数</param>
        /// <returns></returns>
        public List<dynamic> GetList_2(int Top, string Fields, string Where, string Order, params object[] param)
        {
            return dbOperat.GetListSomeField(TableName, Top, Fields, Where, Order, param);
        }

        /// <summary>
        /// 获取列表方法
        /// </summary>
        /// <param name="TableName">指定表名称 , 如果不指定默认当前操作实例化的表</param>
        /// <param name="Top">前几条</param>
        /// <param name="Fields">那些字段</param>
        /// <param name="Where">条件</param>
        /// <param name="Order">排序</param>
        /// <param name="param">参数化语句的参数</param>
        /// <returns></returns>
        public List<dynamic> GetList_3(string TableName, int Top, string Fields, string Where, string Order, params object[] param)
        {
            return dbOperat.GetList(TableName, Top, Fields, Where, Order, param);
        }


        //private List<dynamic> GetListField(string DataBase, string TableName, int Top, string Fields, string Where, string Order, params object[] param)
        //{
        //    return dbOperat.GetList(TableName, Top, Fields, Where, Order, param);
        //}

        #endregion



        #region GetPage 方法 结果中包含总共多少条 --OK


        /// <summary>
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="Where">where</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <param name="IgnoreReleaseTime">是否忽略定时发布 , 用于后台 , true 为忽略定时发布条件 false 可以查找出所有的数据(包括未发布的数据)</param> 
        /// <returns></returns>
        public SysModel.PageModels GetPage_2(int PageSize, int CurPage, string Where, string OrderBy, bool IgnoreReleaseTime = true)
        {
            return dbOperat.GetPage(TableName, null, PageSize, CurPage, Where, OrderBy, IgnoreReleaseTime);
        }
        /// <summary>
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where">where</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <param name="IgnoreReleaseTime">是否忽略定时发布 , 用于后台 , true 为忽略定时发布条件 false 可以查找出所有的数据(包括未发布的数据)</param> 
        /// <returns></returns>
        public SysModel.PageModels GetPage_2(string Fields, int PageSize, int CurPage, string Where, string OrderBy, bool IgnoreReleaseTime = true)
        {
            return dbOperat.GetPage(TableName, Fields, PageSize, CurPage, Where, OrderBy, IgnoreReleaseTime);
        }
        /// <summary>
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where">条件</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <param name="IgnoreReleaseTime">是否忽略定时发布 , 用于后台 , true 为忽略定时发布条件 false 可以查找出所有的数据(包括未发布的数据)</param> 
        /// <returns></returns>
        public SysModel.PageModels GetPage_2(string TableName, string Fields, int PageSize, int CurPage, string Where, string OrderBy, bool IgnoreReleaseTime = true)
        {
            return dbOperat.GetPage(TableName, Fields, PageSize, CurPage, Where, OrderBy, IgnoreReleaseTime);
        }



        /// <summary>
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where">where 条件 不用写where</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <param name="IgnoreReleaseTime">是否忽略定时发布 , 用于后台 , true 为忽略定时发布条件 false 可以查找出所有的数据(包括未发布的数据)</param> 
        /// <returns></returns>
        private SysModel.PageModels GetPageData_2(string TableName, string Fields, int PageSize, int CurPage, string Where, string OrderBy, bool IgnoreReleaseTime = true)
        {
            return dbOperat.GetPage(TableName, Fields, PageSize, CurPage, Where, OrderBy, IgnoreReleaseTime);

        }

        #endregion


        #region GetSearchPage 方法 获取搜索分页数据 --OK


        /// <summary>
        /// 获取搜索分页
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where"></param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <returns></returns>
        public SysModel.PageModels GetSearchPage(int PageSize, int CurPage, string Where, string OrderBy)
        {
            return dbOperat.GetSearchPage(TableName, null, PageSize, CurPage, Where, OrderBy);
        }
        /// <summary>
        /// 获取搜索分页
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where"></param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <returns></returns>
        public SysModel.PageModels GetSearchPage(string Fields, int PageSize, int CurPage, string Where, string OrderBy)
        {
            return dbOperat.GetSearchPage(TableName, Fields, PageSize, CurPage, Where, OrderBy);
        }
        /// <summary>
        /// 获取搜索分页
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where">条件</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <returns></returns>
        public SysModel.PageModels GetSearchPage(string TableName, string Fields, int PageSize, int CurPage, string Where, string OrderBy)
        {
            return dbOperat.GetSearchPage(TableName, Fields, PageSize, CurPage, Where, OrderBy);
        }



        /// <summary>
        /// 获取搜索分页
        /// 获取Page Page不从0开始计算  从1开始计算
        /// 增加总条数参数
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Fields">要取的数据库字段</param>
        /// <param name="PageSize">页大小 最低为1</param>
        /// <param name="CurPage">当前页 最低为1</param>
        /// <param name="Where">where 条件 不用写where</param>
        /// <param name="OrderBy">排序默认使用 ID DESC (ID倒序排列)</param>
        /// <returns></returns>
        private SysModel.PageModels GetSearchPageData(string TableName, string Fields, int PageSize, int CurPage, string Where, string OrderBy)
        {

            return dbOperat.GetSearchPage(TableName, Fields, PageSize, CurPage, Where, OrderBy);
        }

        #endregion


        #region Insert 方法 - OK

        /// <summary>
        /// 新增一条数据 返回新增数据后的Model
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public dynamic InsertReturnModel(dynamic Model)
        {
            return dbOperat.InsertReturnModel(TableName, Model);
        }

        /// <summary>
        /// 新增一条数据 返回新增数据后的Model
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public dynamic InsertReturnModel(dynamic Model, string TableName)
        {
            return dbOperat.InsertReturnModel(TableName, Model);
        }

        /// <summary>
        /// 插入一条数据 返回新增数据的ID
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public int InsertReturnId(dynamic Model)
        {
            return dbOperat.InsertReturnId(TableName, Model);
        }
        /// <summary>
        /// 插入一条数据 返回新增数据的ID
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public int InsertReturnId(dynamic Model, string TableName)
        {
            return dbOperat.InsertReturnId(TableName, Model);
        }
        /// <summary>
        /// 新增一条数据 返回新增数据后的ID
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        private int Insert(dynamic Model, string TableName)
        {

            return dbOperat.InsertReturnId(TableName, Model);
        }

        #endregion

        #region Update 方法 - OK

        /// <summary>
        /// 更新字段  注意SQL字段和参数必须顺序正确
        /// </summary>
        /// <param name="Fields">字段 Title=@Title</param>
        /// <param name="Where">条件 Id=@Id</param>
        /// <param name="param">"TItle",Id</param>
        /// <returns></returns>
        public bool UpdateFields_1(string Fields, string Where, params object[] param)
        {
            return dbOperat.UpdateFields(TableName, Fields, Where, param);
        }
        /// <summary>
        /// 更新字段  注意SQL字段和参数必须顺序正确
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Fields">字段 Title=@Title</param>
        /// <param name="Where">条件 Id=@Id</param>
        /// <param name="param">"TItle",Id</param>
        /// <returns></returns>
        public bool UpdateFields_2(string TableName, string Fields, string Where, params object[] param)
        {
            return dbOperat.UpdateFields(TableName, Fields, Where, param);
        }
        /// <summary>
        /// 更新一个Model, 根据ID
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public bool Update(dynamic Model)
        {
            return dbOperat.Update(TableName, Model);
        }
        /// <summary>
        /// 根据Id更新一个Model
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Model">动态Model</param>
        /// <returns></returns>
        public bool Update(string TableName, dynamic Model)
        {
            return dbOperat.Update(TableName, Model);

        }
        /// <summary>
        /// 更新方法
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Fields">更新的字段值  不能为空</param>
        /// <param name="Where">更新条件 不能为空</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        private bool Update(string TableName, string Fields, string Where, params object[] param)
        {
            return dbOperat.UpdateFields(TableName, Fields, Where, param);


        }
        #endregion

        #region Delete 方法 - OK
        /// <summary>
        /// 数据库删除
        /// </summary>
        /// <param name="Where"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Delete_1(string Where, params object[] param)
        {
            return dbOperat.Delete(TableName, Where, param);
        }
        /// <summary>
        /// 数据库删除
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Where"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Delete_2(string TableName, string Where, params object[] param)
        {
            return dbOperat.Delete(TableName, Where, param);
        }

        /// <summary>
        /// 虚拟删除  [Status]=-1
        /// </summary>
        /// <param name="Where"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Delete_Virtual(string Where, params object[] param)
        {
            return dbOperat.Delete_Virtual(TableName, Where, param);
        }
        /// <summary>
        /// 虚拟删除  [Status]=-1
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Delete_Virtual(int Id, params object[] param)
        {
            return dbOperat.Delete_Virtual(TableName, Id, param);
        }
        /// <summary>
        /// 删除数据 , 数据库删除
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="Where"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        private bool Deletes(string TableName, string Where, params object[] param)
        {
            return dbOperat.Delete(TableName, Where, param);
        }
        #endregion



        /// <summary>
        /// 复制一条数据 . 被复制的表如果没有字段会报错   注意字段大小写区别 
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Id">标识列</param>
        /// <param name="CusFields"></param>
        /// <returns></returns>
        public int CopyData(string TableName, string Id, Dictionary<string, string> CusFields)
        {
            return dbOperat.CopyData(TableName, Id, CusFields);
        }
        /// <summary>
        /// 复制字段表多条数据 . 被复制的表如果没有字段会报错   注意字段大小写区别 
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="ClassId">栏目表的ID</param>
        /// <param name="CusFields">需要替换的字段值 key=字段 value=值</param>
        /// <returns></returns>
        public bool CopyChannelFields(string TableName, string ClassId, Dictionary<string, string> CusFields)
        {
            return dbOperat.CopyChannelFields(TableName, ClassId, CusFields);
        }

        /// <summary>
        /// 复制栏目里面的内容 
        /// <para>复制栏目的时候选择了复制数据,  则可以将被复制的栏目里面的数据也都Copy过来</para>
        /// </summary>
        /// <param name="TabName">栏目内容所属表</param>
        /// <param name="ClassId">栏目ClassId</param>
        /// <param name="CusFields">自定义需要复制的字段</param>
        /// <returns></returns>
        public bool CopyChannelData(string TabName, string ClassId, Dictionary<string, string> CusFields)
        {
            return dbOperat.CopyChannelData(TableName, ClassId, CusFields);
        }

        /// <summary>
        /// 复制模板表多条数据 . 被复制的表如果没有字段会报错   注意字段大小写区别 
        /// <para>复制模板的时候需要复制模板对应的Model</para>
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="ClassId">栏目表的ID</param>
        /// <param name="CusModules"></param>
        /// <returns></returns>
        public bool CopyChannelModules(string TableName, string ClassId, Dictionary<string, string> CusModules)
        {
            return dbOperat.CopyChannelModules(TableName, ClassId, CusModules);
        }


        #region 获取上下一条的方法
        /// <summary>
        /// 获取上一条数据的方法
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public dynamic GetPrev(dynamic Model, string Order, params object[] param)
        {
            return dbOperat.GetPrev(TableName, Model, Order, param);
        }


        /// <summary>
        /// 获取下一跳数据的方法
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Order"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public dynamic GetNext(dynamic Model, string Order, params object[] param)
        {
            return dbOperat.GetNext(TableName, Model, Order, param);
        }



        #endregion


        #region 验证表或者数据库是否存在
        /// <summary>
        /// IsExistTable 表是否存在 
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <returns>是否存在 true 存在  false 不存在</returns>
        public bool IsExistTable(string TableName)
        {
            return dbOperat.IsExistTable(null, TableName);
        }
        /// <summary>
        /// IsExistTable 表是否存在 
        /// </summary>
        /// <param name="DataBase"> 链接字符串 为空标示使用实例化当前DbOperat的数据库</param>
        /// <param name="TableName">表名称</param>
        /// <returns>是否存在 true 存在  false 不存在</returns>
        public bool IsExistTable(string DataBase, string TableName)
        {
            return dbOperat.IsExistTable(DataBase, TableName);
        }

        /// <summary>
        /// 检查表中是否有当前字段 , 使用当前实例的数据库和表
        /// </summary>
        /// <param name="Field">字段名称</param>
        /// <returns>是否存在 true 存在  false 不存在</returns>
        public bool IsExistField(string Field)
        {
            return dbOperat.IsExistField(null, TableName, Field);
        }
        /// <summary>
        /// 检查表中是否有当前字段 使用当前实例的数据库
        /// </summary>
        /// <param name="TableName">表名称</param>
        /// <param name="Field">字段名称</param>
        /// <returns>是否存在 true 存在  false 不存在</returns>
        public bool IsExistField(string TableName, string Field)
        {
            return dbOperat.IsExistField(null, TableName, Field);
        }
        /// <summary>
        /// 检查表中是否有当前字段
        /// </summary>
        /// <param name="DataBase">数据库链接字符串</param>
        /// <param name="TableName">表名称</param>
        /// <param name="Field">字段名称</param>
        /// <returns>是否存在 true 存在  false 不存在</returns>
        public bool IsExistField(string DataBase, string TableName, string Field)
        {
            return dbOperat.IsExistField(DataBase, TableName, Field);

        }
        #endregion

        #region 数据库默认字段
        ///// <summary>
        ///// 获取创建一张表的默认字段 {TableName} 是表名称的参数  SEO的三个字段必须加
        ///// 此中的数据和Fields表中的数据要保持一致
        ///// </summary>
        ///// <returns></returns>
        ////public string GetCreateTableSql(string TableName)
        ////{

        ////}

        ///// <summary>
        ///// 获取添加一个字段的SQL
        ///// </summary>
        ///// <param name="FieldModel"></param>
        ///// <returns></returns>
        ////public string GetCreateFieldSql(SysModel.FieldModel FieldModel)
        ////{

        ////}

        #endregion

        #region 数据库表和字段操作

        ///// <summary>
        ///// 添加表到默认数据库
        ///// </summary>
        ///// <param name="TableName">表名字</param>
        ///// <returns>是否添加成功</returns>
        ////public bool AddTableToDataBase(string TableName)
        ////{

        ////}


        ///// <summary>
        ///// 添加表到指定数据库
        ///// </summary>
        ///// <param name="DataBase">连接字符串</param>
        ///// <param name="TableName">表名字</param>
        ///// <returns>返回是否添加成功</returns>
        ////public bool AddTableToDataBase(string DataBase, string TableName)
        ////{

        ////}

        /// <summary>
        /// 添加字段到默认数据库的指定表
        /// </summary>
        /// <param name="FieldModel"></param>
        /// <returns></returns>
        public bool AddFieldToTable(SysModel.FieldModel FieldModel)
        {
            return dbOperat.AddFieldToTable(FieldModel);
        }

        /// <summary>
        /// 添加字段到指定数据库的指定表
        /// </summary>
        /// <param name="DataBase"></param>
        /// <param name="FieldModel"></param>
        /// <returns></returns>
        public bool AddFieldToTable(string DataBase, SysModel.FieldModel FieldModel)
        {

            return dbOperat.AddFieldToTable(DataBase, FieldModel);
        }


        #endregion

        #region 数据库备份
        /// <summary>
        /// 数据库备份
        /// 备份为脚本文件
        /// </summary>
        /// <param name="connName">链接字符串名称</param>
        /// <param name="filePath">备份路径(站点根目录)</param>
        /// <returns></returns>
        public bool BackUpDataBase(string connName = "", string filePath = "")
        {
            return dbOperat.BackUpDataBase(connName, filePath);
        }
        #endregion


        #region 直接执行SQL语句
        /// <summary>
        /// 执行SQL语句 返回List
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public DataTable ExecSqlCmd_Table(string sql, params object[] param)
        {
            return dbOperat.ExecSqlCmd_Table(sql, param);
        }

        /// <summary>
        /// 执行SQL语句 返回单行数据
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public DataRow ExecSqlCmd_Row(string sql, params object[] param)
        {
            return dbOperat.ExecSqlCmd_Row(sql, param);
        }

        /// <summary>
        /// 执行SQL语句 返回第一行第一列
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public object ExecSqlCmd_Object(string sql, params object[] param)
        {
            return dbOperat.ExecSqlCmd_Object(sql, param);
        }

        /// <summary>
        /// 执行SQL语句 返回是否执行成功
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public int ExecSqlCmd_NonQuery(string sql, params object[] param)
        {
            return dbOperat.ExecSqlCmd_NonQuery(sql, param);
        }
        #endregion

        #region 直接执行存储过程
        /// <summary>
        /// 执行SQL存储过程 返回List
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public DataTable ExecSqlProceducre_Table(string sql, params object[] param)
        {
            return dbOperat.ExecSqlProceducre_Table(sql, param);
        }

        /// <summary>
        /// 执行SQL存储过程 返回单行数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public DataRow ExecSqlProceducre_Row(string sql, params object[] param)
        {
            return dbOperat.ExecSqlProceducre_Row(sql, param);
        }

        /// <summary>
        /// 执行SQL存储过程 返回第一行第一列
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public object ExecSqlProceducre_Object(string sql, params object[] param)
        {
            return dbOperat.ExecSqlProceducre_Object(sql, param);
        }

        /// <summary>
        /// 执行SQL存储过程 返回是否执行成功
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public int ExecSqlProceducre_NonQuery(string sql, params object[] param)
        {
            return dbOperat.ExecSqlProceducre_NonQuery(sql, param);
        }
        #endregion





    }



}
